const { regeneratorRuntime, connect, P } = global

Page(global.connect(
  state => ({
    ...state.globalReducer,
    ...state.profileReducer
  }),
  dispatch => ({
    handleRoute: global.handleRoute,
    async userLogout(data) {
      return dispatch(global.profileReducer.userLogout(data))
    }
  })
)(P({
  data: {
  },
  onLoad() {
    console.log(`${this.route} onLoad`)
  },
  async handleLogout() {
    try {
      const { openid, user_type } = this.data.minaLoginRes.data
      const actionRes = await this.userLogout({
        openid, user_type
      })
      if (actionRes.actionStatus === 'SUCCESS') {
        wx.removeStorageSync('openid')
        wx.reLaunch({
          url: "/pages/login/login"
        })
      } else {
        this.selectComponent('#toast').handleShow({
          message: actionRes.apiMes || '退出失败，请稍后再试'
        })
      }
    } catch (error) {
      console.error(error)
      this.selectComponent('#toast').handleShow({
        message: error.apiMes || '退出失败，请稍后再试'
      })
    }
  },
  handleLicon1Tap(e) {
    console.log('handleLicon1Tap', e)
    wx.navigateBack()
  },
  handleTap(e) {
    console.log('handleTap', e)
    const { route, avatar } = e.currentTarget.dataset
    if (route) {
      this.handleRoute(e)
    }
    if (avatar) {
      this.handleAvatar(e)
    }
  },
  handleAvatar(e) {
    console.log('handleAvatar', e)
  }
})))